package org.qqcui.designpattern.patterns.flyweight;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 网站的工厂类
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2022/5/1 9:21
 **/
public class WebsiteFactory {

    /**
     * 网站的资源缓存池，如果该资源池中已经存在该类型的网站，不会重新创建，直接返回，如果不存在该类型的网站，创建并缓存
     */
    private Map<String, Website> pool = new ConcurrentHashMap<>();

    public Website getWebsiteCatagory(String type) {
        if (!pool.containsKey(type)) {
            pool.put(type, new ConcreteWebsite(type));
        }
        return pool.get(type);
    }

    public int getWebsiteCount() {
        return pool.size();
    }
}
